home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_ircd-hybrid.idb / etc / init.d / ircd.z / ircd
Text File  |  2001-10-09  |  3KB  |  131 lines

  1. #!/bin/sh
  2.  
  3. # Start Internet Relay Chat Daemon
  4. # --srosa/SGI
  5. # "$revision: 2.0 $"
  6.  
  7. IS_ON="/sbin/chkconfig"
  8. UID="/usr/bin/id"
  9. LS="/usr/bin/ls"
  10. NAWK="/bin/nawk"
  11. GREP="/bin/grep"
  12.  
  13. if [ ! -x $IS_ON -o ! -x $UID -o ! -x $LS -o ! -x $GREP ]; then
  14.    echo "ERROR: some tools needed by the ircd init script are not available. aborted."
  15.    exit 1
  16. fi
  17.  
  18. if $IS_ON verbose ; then
  19.     ECHO=echo
  20. else
  21.     ECHO=:
  22. fi
  23.  
  24. CONFIG=/etc/config
  25. BINDIR=/usr/freeware/bin
  26. LIBDIR=/usr/freeware/lib/ircd
  27. HYBDIR=${LIBDIR}/hybserv
  28.  
  29. Start_Server() {
  30.    if $IS_ON ircd; then
  31.  
  32.       # Check out that a specific user has been created. The daemon MUST NOT
  33.       # run as root.
  34.       if ! $UID ircadmin > /dev/null 2>&1; then
  35.          $ECHO "\nERROR: user ircadmin does not exist. Cannot start ircd server."
  36.          exit 0 
  37.       fi
  38.  
  39.       # Check out that ownership/permissions are ok, or try to fix it. swmgr
  40.       # installs the package as root by default.
  41.       if ! $LS -l ${BINDIR}/ircd | $GREP -q -e "rws.*ircadmin" > /dev/null 2>&1; then
  42.          $ECHO "\nERROR: ircd server files MUST belong to user ircadmin. Trying to fix it."
  43.          if ! ${LIBDIR}/fixperms > /dev/null 2>&1; then
  44.             $ECHO "\nERROR: chown failed. Fix it manually. Cannot start ircd server."
  45.             exit 0
  46.          fi
  47.       fi
  48.  
  49.       # If everything seems right, start the daemon
  50.       $ECHO "Starting Internet Relay Chat daemon:\c"
  51.       ${BINDIR}/ircd `cat ${CONFIG}/ircd.options 2> /dev/null`
  52.       $ECHO " ircd\c"
  53.  
  54.       # If it is installed and enabled, wait a bit for the irc daemon to
  55.       # come up, then start the HybServ IRC Services daemon (NickServ, etc)
  56.  
  57.       if [ -d $HYBDIR -a -x ${HYBDIR}/hybserv ]; then
  58.          if $IS_ON hybserv; then
  59.  
  60.             # Check out that ownership/permissions are ok there as well, in
  61.             # case hybserv has been installed after ircd's first run
  62.             if ! $LS -l ${HYBDIR}/hybserv | $GREP -q -e "rws.*ircadmin" > /dev/null 2>&1; then
  63.                $ECHO "\nERROR: hybserv files MUST belong to user ircadmin. Trying to fix it."
  64.                if ! ${LIBDIR}/fixperms > /dev/null 2>&1; then
  65.                   $ECHO "\nERROR: chown failed. Fix it manually. Cannot start hybserv services."
  66.                   exit 0
  67.                fi
  68.             fi
  69.  
  70.             # If everything seems right, start the daemon
  71.             sleep 10
  72.             su ircadmin -c "${HYBDIR}/hybserv" > /dev/null 2>&1
  73.             $ECHO " hybserv\c"
  74.          fi
  75.       fi
  76.       
  77.       # if the autostart file for bots is there, launch all bots in it
  78.       if [ -x $NAWK -a -r ${CONFIG}/ircdbots.config ]; then
  79.          su ircadmin -c "$NAWK -f ${CONFIG}/ircdbots.nawk ${CONFIG}/ircdbots.config"
  80.       fi
  81.  
  82.       $ECHO "."
  83.  
  84.       exit 0
  85.    fi
  86. }
  87.  
  88.  
  89. Stop_Server() {
  90.    $ECHO "Shutting down Internet Relay Chat daemon."
  91.    
  92.    if [ -x $NAWK -a -r ${LIBDIR}/ircdbots.pid ]; then
  93.       $NAWK -f ${CONFIG}/ircdbots.nawk ${LIBDIR}/ircdbots.pid
  94.    fi
  95.  
  96.    if [ -r ${HYBDIR}/hybserv.pid ]; then
  97.       kill -TERM `head -1 ${HYBDIR}/hybserv.pid` > /dev/null 2>&1
  98.       rm ${HYBDIR}/hybserv.pid
  99.    fi
  100.  
  101.    sleep 5
  102.  
  103.    if [ -r ${LIBDIR}/ircd.pid ]; then
  104.       kill -TERM `head -1 ${LIBDIR}/ircd.pid` > /dev/null 2>&1
  105.       rm ${LIBDIR}/ircd.pid
  106.    fi
  107. }
  108.  
  109. case "$1" in
  110.  
  111. 'start')
  112.    Start_Server
  113.    ;;
  114.  
  115. 'stop')
  116.    Stop_Server
  117.    ;;
  118.  
  119. 'restart')
  120.    Stop_Server
  121.    Start_Server
  122.    ;;
  123.  
  124. *)
  125.    echo "usage: /etc/init.d/ircd {start|stop|restart}"
  126.    ;;
  127.  
  128. esac
  129.  
  130. exit 0
  131.